public class DynamicTree {
    //创建动态二叉树
    public TreeNode node;

    public TreeNode getNode() {
        return node;
    }

    public void setNode(TreeNode node) {
        this.node = node;
    }

    public static void createTree(DynamicTree node, int value){
        if (node.getNode()==null){
            TreeNode newNode = new TreeNode(value);
            node.setNode(newNode);
        }
        else{
            TreeNode newNode=node.getNode();
            while(newNode!=null){
                if (value> newNode.getData()){
                    if (newNode.getRightNode()==null){
                        newNode.setRightNode(new TreeNode(value));
                    }
                    else{
                        newNode=newNode.getRightNode();
                    }
                }
                else{
                    if (newNode.getLeftNode()==null){
                        newNode.setLeftNode(new TreeNode(value));
                    }
                    else{
                        newNode=newNode.getLeftNode();
                    }
                }
            }
        }
    }
}
